﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StarryEdge.Menu.SettingSystem.ViewModels.Dialog
{
    public class NewLanguagePopupDialog : Prism.Mvvm.BindableBase
    {
        private string _name;

        public string Name
        {
            get { return _name; }
            set { SetProperty(ref _name, value); }
        }

        private string _ImageName;

        public string ImageName
        {
            get { return _ImageName; }
            set { SetProperty(ref _ImageName, value); }
        }

        private LanguageDictionaryViewModel _LanguageViewModel;

        public NewLanguagePopupDialog(LanguageDictionaryViewModel languageDictionary)
        {
            ImageName = "选择图片";
            _LanguageViewModel = languageDictionary;
        }

        public DelegateCommand SelectPicture => new DelegateCommand(() =>
        {
            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
            openFileDialog.Title = "选择图片";
            openFileDialog.Filter = "PNG文件(*.png)|*.png";
            openFileDialog.FileName = "选择图片";
            openFileDialog.FilterIndex = 1;
            openFileDialog.ValidateNames = false;
            openFileDialog.CheckFileExists = false;
            openFileDialog.CheckPathExists = true;
            openFileDialog.Multiselect = false;//允许同时选择多个文件
            if (openFileDialog.ShowDialog() == true)
            {
                ImageName = System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName);
                string imagepath = $"Resource\\Flag\\{ImageName}.png";
                File.Move(openFileDialog.FileName, Path.Combine(Environment.CurrentDirectory, imagepath));
                var model = new Core.Models.LanguageFileInfoModel()
                {
                    ImagePath = imagepath,
                    Lang = ImageName,
                    ToolTip = ImageName,
                    Name = Name,
                };
                _LanguageViewModel.LangList.Add(model);
                _LanguageViewModel.EditLang = model;
            }
        });

        public DelegateCommand Save => new DelegateCommand(() =>
        {
            _LanguageViewModel.SaveLangInfo();
            DialogHost.Close("Global");
        });
    }
}
